package proxy.test;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @author 帅小伙
 * @date 2022/3/8
 * @description
 */
public class ProxyFac {

    Object target;

    public ProxyFac(Object target) {
        this.target = target;
    }


    public Object getProxyInstance(){
        return Proxy.newProxyInstance(target.getClass().getClassLoader(),
                target.getClass().getInterfaces(),
                new InvocationHandler() {
                    @Override
                    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                        System.out.println("代理前");
                        Object invoke = method.invoke(target, args);
                        System.out.println("代理后");
                        return invoke;
                    }
                });
    }
}
